﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Cors;

namespace LdCms.Web.Controllers.API.Sys.V1
{
    using LdCms.EF.DbModels;
    using LdCms.IBLL.Log;
    using LdCms.IBLL.Sys;
    using LdCms.Web.Services;

    /// <summary>
    /// 系统配置接口：
    ///     01、获取系统配置参数
    ///         GET：sys/config/get?uuid=e25d94c4db3c468098b34b55a52cc89d
    /// 
    /// </summary>
    [ApiVersion("1.0")]
    [ControllerName("sys/config")]
    public partial class SysConfigController : BaseApiController
    {
        private readonly IBaseApiManager BaseApiManager;
        private readonly IConfigService ConfigService;
        public SysConfigController(IBaseApiManager BaseApiManager, IConfigService ConfigService) : base(BaseApiManager)
        {
            this.BaseApiManager = BaseApiManager;
            this.ConfigService = ConfigService;
        }

        [HttpGet]
        [ActionName("get")]
        public IActionResult GetConfig(string uuid)
        {
            long logId = 0;
            try
            {
                logId = BaseApiManager.SaveLogs(uuid);
                string companyId = InterfaceAccount.CompanyID;
                var result = ConfigService.GetConfig(SystemID, companyId);
                if (result == null)
                    return Error(logId, "uuid invalid！");
                var data = new
                {
                    title = result.Title,
                    keywords = result.Keyword,
                    description = result.Description,
                    copyright = result.Copyright,
                    icp = result.IcpNumber,
                    statistics_code = result.StatisticsCode
                };
                return Success(logId, "ok", data);
            }
            catch (Exception ex)
            {
                return Error(logId, ex.Message);
            }
        }



    }
}